<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>PlanarGC: Tutorial: CutShape</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">PlanarGC
   &#160;<span id="projectnumber">1.0.2</span>
   </div>
  </td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.2 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('a00008.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Tutorial: <a class="el" href="a00016.html">CutShape</a> </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><a class="el" href="a00016.html">CutShape</a> finds an optimal matching between two shapes via a graph cut. The only thing the user has to provide is a quadratic dissimilarity matrix where the non-negative value at position (i,j) describes the dissimilarity between the point i on the first shape and the point j on the second shape.</p>
<div class="image">
<img src="dissim.PNG" alt="dissim.PNG"/>
<div class="caption">
Example of a dissimilarity matrix</div></div>
<p>In order to compute the optimal matching (which is a cut in a specific planar graph), the following steps have to be performed:</p>
<ol type="1">
<li>Define the <a class="el" href="a00008.html#sec_gradientShp">dissimilarity matrix</a>.</li>
<li>Compute the <a class="el" href="a00008.html#sec_matchingShp">matching score</a>.</li>
<li><a class="el" href="a00008.html#sec_getcutShp">Extract the optimal matching</a>.</li>
</ol>
<p>In the following sections, we explain these steps with respect to the graph sketched in the images above.</p>
<h1><a class="anchor" id="sec_gradientShp"></a>
Dissimilarity Matrix</h1>
<p>After computing a nxn dissimilarity of every point pair, we just have to provide this information to the <a class="el" href="a00016.html">CutShape</a> instance: </p>
<div class="fragment"><div class="line"><a class="code" href="a00016.html">CutShape</a> shape_cut;</div>
<div class="line"></div>
<div class="line">shape_cut.<a class="code" href="a00016.html#a39a6a0ce3f60a9be1318d267d37a355b">setDissimilarityMatrix</a>(n, dissim);</div>
</div><!-- fragment --><h1><a class="anchor" id="sec_matchingShp"></a>
Matching Score</h1>
<p>Now that the problem is formulated, we have to compute the matching score. This is the most time consuming method of the class and is called via</p>
<div class="fragment"><div class="line"><span class="keywordtype">double</span> score;</div>
<div class="line"></div>
<div class="line">score = shape_cut.<a class="code" href="a00016.html#a8759740ccadb605b22d924f2c0c9f450">getMatchingScore</a>();</div>
</div><!-- fragment --><h1><a class="anchor" id="sec_getcutShp"></a>
Optimal Matching</h1>
<p>In order to receive the matching, we just have to extract it via: </p>
<div class="fragment"><div class="line">vector&lt; pair&lt;int,int&gt; &gt; matching;</div>
<div class="line"></div>
<div class="line">matching = shape_cut.<a class="code" href="a00016.html#a6880ca2298450793d473522c20a7eed3">getMatching</a>();           </div>
</div><!-- fragment --><p>The complete code can be seen here: <a class="el" href="a00004.html">cutshape.cpp</a>. </p>
</div></div><!-- contents -->
</div><!-- doc-content -->
<hr class="footer"/><address style="text-align: right;"><small>
  &copy; 2009 - 2013 by Eno T&ouml;ppe, Frank R. Schmidt
  <br/>
  generated by <a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a>
</small></address>
